import Vue from 'vue'
import Router from 'vue-router'
import main from '@/components/main'
import edit from '@/components/edit'
import payPage from '@/components/payPage'
import buildingEdit from '@/components/buildingEdit'
import detailPage from '@/components/detailPage'
import setPassword from '@/components/setPassword'
import upVideo from '@/components/upVideo'
import car from '@/components/car'
import message from '@/components/message'
import video from '@/components/video'
import photo from '@/components/photo'
import music from '@/components/music'
import strightVideo from '@/components/strightVideo'
import musicList from '@/components/musicList'
import jininaguan from '@/components/jinianguan'
import list from '@/components/list'
import sacrifice from '@/components/sacrifice'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'main',
      component: main
    },
    {
      path: '/edit',
      name: 'edit',
      component: edit
    },
    {
      path: '/pay-page',
      name: 'payPage',
      component: payPage
    },
    {
      path: '/building-edit',
      name: 'buildingEdit',
      component: buildingEdit
    },
    {
      path: '/detail-page',
      name: 'detailPage',
      component: detailPage
    },
    {
      path: '/set-password',
      name: 'setPassword',
      component: setPassword
    },
    {
      path: '/up-video',
      name: 'upVideo',
      component: upVideo
    },
    {
      path: '/car',
      name: 'car',
      component: car
    },
    {
      path: '/message',
      name: 'message',
      component: message
    },
    {
      path: '/video',
      name: 'video',
      component: video
    },
    {
      path: '/photo',
      name: 'photo',
      component: photo
    },
    {
      path: '/music',
      name: 'music',
      component: music
    },
    {
      path: '/stright-video',
      name: 'strightVideo',
      component: strightVideo
    },
    {
      path: '/music-list',
      name: 'musicList',
      component: musicList
    },
    {
      path: '/jininaguan',
      name: 'jininaguan',
      component: jininaguan
    },
    {
      path: '/list',
      name: 'list',
      component: list
    },
    {
      path: '/sacrifice',
      name: 'sacrifice',
      component: sacrifice
    }
  ]
})

let toBuildingRouterPath = null

router.beforeEach((to, from, next) => {
  if (from.name === null) {
    window.localStorage.setItem('toBuildingRouterPath', '/')
    next()
    return
  }
  if (to.name === 'buildingEdit' && from.name !== 'musicList') {
    window.localStorage.setItem('toBuildingRouterPath', from.fullPath)
  }
  next()
})

export default router
